package com.learn.product;

import java.util.List;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.learn.product.ProductApi.ProductApiFallback;
import com.learn.product.dto.CartDTO;
import com.learn.product.dto.ProductInfoDTO;
import com.learn.product.dto.ResultDTO;
import com.learn.product.enums.ResultEnum;

@FeignClient(name = "product", fallback = ProductApiFallback.class)
public interface ProductApi {

	@PostMapping("listForOrder")
	public ResultDTO<List<ProductInfoDTO>> listForOrder(@RequestBody List<String> productIds);

	@PostMapping("decreaseStock")
	public ResultDTO<ResultEnum> decreaseStock(@RequestBody List<CartDTO> cartDTOS);

	@Component
	public static class ProductApiFallback implements ProductApi {
		@Override
		public ResultDTO<List<ProductInfoDTO>> listForOrder(List<String> productIds) {
			return null;
		}

		@Override
		public ResultDTO<ResultEnum> decreaseStock(List<CartDTO> cartDTOS) {
			return null;
		}

	}
}
